package jzq.spring.annotation;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author jzq
 * @date 2019/3/14 14:06
 */
public class AnnotationApp {

    @Test
    public void test() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        Student student = (Student) context.getBean("student");
        System.out.println(student.toString());
    }

//    用 @Qualifier 注释和 @Autowired来指定bean
    @Test
    public void constructorTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        Clazz clazz = (Clazz) context.getBean("clazz");
        System.out.println(clazz.getStudent().getName());
    }

    @Test
    public void configurationTest () {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        Person person = ctx.getBean(Person.class);
        person.setName("jzq");
        System.out.println(person.getName());

    }
}
